package com.cnsoft.model.company;

import javax.annotation.Resource;

import org.cnsoft.framework.beans.common.RESTResultBean;
import org.cnsoft.framework.constants.ECCodeMessageConstants;
import org.cnsoft.framework.db.page.PageModel;
import org.cnsoft.framework.support.MyPageControllerSupport;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.cnsoft.persistent.company.C201110Manager.C201110ManagerDBO;
import com.cnsoft.persistent.company.C201110Manager.C201110ManagerDao;
import com.cnsoft.persistent.company.C201110Manager.C201110ManagerPVO;

/**
 * 企业员工登录账户表页面控制逻辑
 */
@Controller
@RequestMapping(value = "/page/1.0/base/c201110manager", method = { RequestMethod.POST })
public class C201110ManagerPageController extends MyPageControllerSupport { // MyTokenCommonSupport
	@Resource
	private C201110ManagerDao daoC201110Manager;

	// private MyModelAndViewSupport model =
	// super.getModelAndView("C201110_manager");

	// 一览（分页查询）
	@RequestMapping(value = "/list", method = RequestMethod.POST)
	public ModelAndView doList(C201110ManagerPVO param, PageModel<C201110ManagerDBO> pageModel, RESTResultBean<String> message) throws Exception {
		// 输出参数日志
		logger.debug("param=====>>>>" + param.toJsonString());
		// 设定展示界面
		ModelAndView modelAndView = getModelAndView("/company/C201110Manager-list");
		pageModel.setFormParamBean(param);
		// 开启记录数统计
		// pageModel.setResultCountFlag(true);
		// 排序模式
		// pageModel.setOrderbyCreateTimeDESC();
		// 分页查询
		daoC201110Manager.doSelectPage(pageModel);
		// 设定返回
		modelAndView.addObject("page", pageModel);
		modelAndView.addObject("param", param);
		modelAndView.addObject("message", message);
		return modelAndView;
	}

	// 打开新增页面
	@RequestMapping(value = "/append", method = RequestMethod.POST)
	public ModelAndView doAppend(C201110ManagerPVO param, PageModel<C201110ManagerDBO> pageModel, RESTResultBean<String> message) throws Exception {
		// 设定展示界面
		ModelAndView modelAndView = getModelAndView("/company/C201110Manager-item");
		// 页面模式设定
		modelAndView.addObject("mode", ONE);
		return modelAndView;
	}

	// 打开编辑页面
	@RequestMapping(value = "/modify", method = RequestMethod.POST)
	public ModelAndView doModify(C201110ManagerPVO param, PageModel<C201110ManagerDBO> pageModel, RESTResultBean<String> message) throws Exception {
		// 输出参数日志
		logger.debug("param=====>>>>" + param.toJsonString());
		// 设定展示界面
		ModelAndView modelAndView = getModelAndView("/company/C201110Manager-item");
		// 页面模式设定
		modelAndView.addObject("mode", TWO);
		// 数据查询
		modelAndView.addObject("data", daoC201110Manager.doRead(param));
		return modelAndView;
	}

	// 删除数据
	@RequestMapping(value = "/discard", method = RequestMethod.POST)
	public ModelAndView doDiscard(C201110ManagerPVO param, PageModel<C201110ManagerDBO> pageModel, RESTResultBean<String> message) throws Exception {
		// 输出参数日志
		logger.debug("param=====>>>>" + param.toJsonString());
		// 信息删除
		daoC201110Manager.doDelete(param);
		message.setResult(ECCodeMessageConstants.MESSAGE_DB_DELETE);
		return doList(new C201110ManagerPVO(), pageModel, message);
	}

	// 数据保存
	@RequestMapping(value = "/save", method = RequestMethod.POST)
	public ModelAndView doSave(String mode, C201110ManagerPVO param, PageModel<C201110ManagerDBO> pageModel, RESTResultBean<String> message) throws Exception {
		// 输出参数日志
		logger.debug("param=====>>>>" + param.toJsonString());
		// 判断操作类别
		if (ONE.equals(mode)) { // 新增
			daoC201110Manager.doInsertSelective(param);
			message.setResult(ECCodeMessageConstants.MESSAGE_DB_INSERT);
		} else { // 编辑
			daoC201110Manager.doUpdate(param);
			message.setResult(ECCodeMessageConstants.MESSAGE_DB_UPDATE);
		}
		// 设定展示界面
		ModelAndView modelAndView = getModelAndView("/communal/pageform-saas");
		// 页面提示信息设定
		modelAndView.addObject("message", message);
		// 目标展示页面
		modelAndView.addObject("target", "/page/1.0/base/c201110manager/list");
		return modelAndView;
	}

}
